package com.ssm.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.sfzy.entity.HeartKnowledge;
import com.ssm.sfzy.mapper.HeartKnowledgeMapper;
import com.ssm.sfzy.service.HeartKnowledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author fuyanru
 * @date 2024年03月30日 9:56
 */
@Service
public class HeartKnowledgeServiceImpl implements HeartKnowledgeService {
    @Autowired
    private HeartKnowledgeMapper heartKnowledgeMapper;
    @Override
    public void add(HeartKnowledge entity){
         heartKnowledgeMapper.insert(entity);
    }

    @Override
    public void edit(HeartKnowledge entity) {
          heartKnowledgeMapper.update(entity);
    }

    @Override
    public void remove(Integer id) {
         heartKnowledgeMapper.delete(id);
    }

    @Override
    public void removeBatch(Integer[] ids) {
        heartKnowledgeMapper.deleteBatch(ids);
    }

    @Override
    public List<HeartKnowledge> find(HeartKnowledge entity) {
        return heartKnowledgeMapper.select(entity);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, HeartKnowledge entity) {
        PageHelper.startPage(pageNum,pageSize);
        List<HeartKnowledge> list = heartKnowledgeMapper.select(entity);
        //
        PageInfo<HeartKnowledge> pageInfo = new PageInfo<>(list);
        // 整合处理
        Map<String,Object> map = new HashMap<>();
        map.put("list",pageInfo.getList());
        map.put("total",pageInfo.getTotal());
        return map;
    }

    @Override
    public HeartKnowledge findById(Integer id) {
        return heartKnowledgeMapper.selectById(id);
    }
}
